package com.rocksea.app.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by 吴志华 on 2017/9/19.
 *
 */

public class FragmentAdapter extends FragmentPagerAdapter
{
    private String[] titles;
    private List<Fragment> mFragments;

    public FragmentAdapter(FragmentManager fm)
    {
        super(fm);
    }

    public void setFragments(List<Fragment> fragments)
    {
        mFragments = fragments;
    }
    @Override
    public Fragment getItem(int position)
    {
        return mFragments.get(position);
    }

    @Override
    public int getCount() {
        return mFragments.size();
    }
    @Override
    public Object instantiateItem(ViewGroup container, int position)
    {
        Fragment fragment;
        fragment = (Fragment) super.instantiateItem(container,position);
        return fragment;
    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object)
    {
        super.destroyItem(container, position, object);
    }

    @Override
    public CharSequence getPageTitle(int position)
    {
        return titles[position];
    }

    public void setTitles(String[] titles)
    {
        this.titles = titles;
    }
}
